package com.qf.controller;

import com.qf.bean.article.dto.Dratf;
import com.qf.dto.R;
import com.qf.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 *  @author Administrator
 *  @version V1.0
 *  @Project banwoqiche
 *  @Package com.qf.controller
 *  @Description
 *  @Date2022/3/30 0030 21:59
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    private ArticleService articleService;

    @Autowired
    public void setArticleService(ArticleService articleService) {
        this.articleService = articleService;
    }
    //查询所有的资讯
    @GetMapping("/all")
    public R findAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
        return R.setOk(articleService.findAll(page, limit));
    }

    //查询所有草稿箱里的
    @GetMapping("/drafts")
    public R findDrafts(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit) {
        return R.setOk(articleService.findDrafts(page, limit));
    }
    //提交草稿箱里的资讯
    @GetMapping("/drafts/submit/{articleId}")
    public R submitDrafts(@PathVariable Integer articleId) {
        return R.setOk(articleService.submitDrafts(articleId));
    }
    //删除草稿箱里的资讯
    @GetMapping("/drafts/delete/{articleId}")
    public R deleteDraft(@PathVariable Integer articleId) {
        return R.setOk(articleService.deleteDraft(articleId));
    }
    //查询草稿箱里被编辑的填充信息
    @GetMapping("/drafts/select/{articleId}")
    public R selectDratf(@PathVariable Integer articleId) {
        return R.setOk(articleService.selectDratf(articleId));
    }
    //修改草稿箱资讯里的信息
    @GetMapping("/drafts/select/{articleId}")
    public R updateDratf(@PathVariable Integer articleId,@RequestBody Dratf dratf) {
        int i = articleService.updateDratf(articleId, dratf);
        return R.setOk("更新了"+i+"条数据");
    }




    //查询所有资讯审核
    @GetMapping("/audit")
    public R findAudit(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
        return R.setOk(articleService.findAudit(page, limit));
    }

    //查询所有发布
    @GetMapping("/issue")
    public R findIssue(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
        return R.setOk(articleService.findAudit(page, limit));
    }

    //查询所有资讯标签
    @GetMapping("/tag")
    public R findAllTag() {
        return R.setOk(articleService.findAllTag());
    }

    //查询所有资讯分类
    @GetMapping("/category")
    public R findAllCategory() {
        return R.setOk(articleService.findAllCategory());
    }


    //查询所有资讯分类
    @GetMapping("/action")
    public R findAction() {
        return R.setOk(articleService.findAction());
    }
}
